home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WUNZ20SR.ZIP / UPDATELB.C < prev    next >
C/C++ Source or Header  |  1992-07-02  |  4KB  |  106 lines

  1. #include "wizunzip.h"
  2. #include "unzip.h"     
  3.  
  4. /* updatelb.c module of WizUnzip.
  5.  * Author: Robert A. Heath
  6.  * I, Robert Heath, place this source code module in the public domain.
  7.  */
  8.  
  9. /* Update Buttons is called when an event possibly modifies the 
  10.  * number of selected items in the listbox. 
  11.  * The function reads the number of selected items. 
  12.  * A non-zero value enables relevant buttons and menu items.
  13.  * A zero value disables them.
  14.  */
  15. void
  16. UpdateButtons(HWND hWnd)
  17. {
  18.     BOOL fButtonState;
  19.  
  20.     if (lpumb->szFileName[0] &&
  21.         SendMessage(hWndList, LB_GETSELCOUNT, 0, 0L)) /* anything selected ? */
  22.     {
  23.         fButtonState = TRUE;
  24.     }
  25.     else
  26.     {
  27.         fButtonState = FALSE;
  28.     }
  29.     EnableWindow(hExtract, fButtonState);
  30.     EnableWindow(hDisplay, fButtonState);
  31.     EnableWindow(hTest, fButtonState);
  32.     EnableWindow(hShowComment, (BOOL)(lpumb->szFileName[0] && cchComment ? TRUE : FALSE));
  33. }
  34.  
  35. /* Update List Box attempts to fill the list box on the parent
  36.  * window with the next "cListBoxLines" of personal data from the 
  37.  * current position in the file.
  38.  * UpdateListBox() assumes that the a record has been read in when called.
  39.  * The cZippedFiles variable indicates whether or not a record exists.
  40.  * The bForward parameter controls whether updating precedes forward
  41.  * or reverse.
  42.  */
  43. void
  44. UpdateListBox(HWND hWnd)
  45. {
  46.     SendMessage(hWndList, LB_RESETCONTENT, 0, 0L);
  47.     InvalidateRect( hWndList, NULL, TRUE );
  48.     UpdateWindow( hWndList );
  49.     cZippedFiles = 0;
  50.  
  51.     if (lpumb->szFileName[0])       /* file selected? */
  52.     {
  53.         /* if so -- stuff list box              */
  54.         SendMessage(hWndList, WM_SETREDRAW, FALSE, 0L);
  55.         if (FSetUpToProcessZipFile(0, 0, 
  56.                 (int)(!uf.fFormatLong ? 1 : 2), 1, 0, 0, 0, 0,
  57.                             0, lpumb->szFileName, NULL))
  58.         {
  59.             process_zipfile();
  60.         }
  61.         else
  62.         {
  63.             MessageBox(hWndMain, szNoMemory, NULL, 
  64.                         MB_OK|MB_ICONEXCLAMATION);
  65.         }
  66.         
  67.         TakeDownFromProcessZipFile();
  68. #ifndef NEED_EARLY_REDRAW
  69.         SendMessage(hWndList, WM_SETREDRAW, TRUE, 0L);
  70.         InvalidateRect(hWndList, NULL, TRUE);   /* force redraw         */
  71. #endif
  72.         cZippedFiles = (WORD)SendMessage(hWndList, LB_GETCOUNT, 0, 0L);
  73.         assert((int)cZippedFiles != LB_ERR);
  74.         if (cZippedFiles)   /* if anything went into listbox set to top */
  75.         {
  76. #ifdef NEED_EARLY_REDRAW
  77.             UpdateWindow(hWndList); /* paint now!                   */
  78. #endif
  79.             SendMessage(hWndList, LB_SETTOPINDEX, 0, 0L);
  80.         }
  81. #ifdef NEED_EARLY_REDRAW
  82.         else /* no files were unarchived!                           */
  83.         {
  84.             /* Add dummy message to initialize list box then clear it
  85.              * to prevent strange problem where later calls to 
  86.              * UpdateListBox() do not result in displaying of all contents.
  87.              */
  88.             SendMessage(hWndList, LB_ADDSTRING, 0, (LONG)(LPSTR)" ");
  89.             UpdateWindow(hWndList); /* paint now!                   */
  90.         }
  91. #endif
  92.     }
  93. #ifdef NEED_EARLY_REDRAW
  94.     else
  95.     {
  96.         /* Add dummy message to initialize list box then clear it
  97.          * to prevent strange problem where later calls to 
  98.          * UpdateListBox() do not result in displaying of all contents.
  99.          */
  100.         SendMessage(hWndList, LB_ADDSTRING, 0, (LONG)(LPSTR)" ");
  101.         UpdateWindow(hWndList); /* paint now!                   */
  102.     }
  103. #endif
  104.  
  105. }
  106.